#!/bin/bash -e

function info() {
echo Usage: `basename $0` [-s sample_name] [-p out_prefix] [-b bed] reads1.fq [reads2.fq]
exit 1
}

while getopts  ":s:p:b:" opts
do
    case  $opts  in
        s) sample_name=$OPTARG;;
        p) out_prefix=$OPTARG;;
        b) bed=$OPTARG;;
    esac
done
shift $(($OPTIND - 1))

if [ $# -lt 1 ]; then info; fi

. $var

read_group=\
@RG\\tID:${sample_name}\\tPL:ILLUMINA\\tSM:$sample_name

reads_seq_1=$1
reads_seq_2=$2
 
echo; echo; echo start bwa mem ...
$bwa mem -p -M -t 8 -R $read_group $ref_genome \
$reads_seq_1 \
$reads_seq_2 \
> $out_prefix.sam

samtools view -b -@6 -f2 -L $bed $out_prefix.sam > $out_prefix.bam

sort_idx_sam.sh -p$out_prefix $out_prefix.bam


. $cmd_done


